package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.util.MapperUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImp implements UserService {

    @Override
    public User login(String email, String password) {
        //用mybatis与数据库连接
        SqlSession session = MapperUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        //调用持久层方法
        User user=mapper.selectByemailPwd(email,password);
        MapperUtil.close(session);
        return user;
    }

    @Override
    public List<User> findAll() {
        //用mybatis与数据库连接
        SqlSession session = MapperUtil.getSession();
        UserMapper mapper = session.getMapper(UserMapper.class);
        //调用持久层方法
        List<User> list=mapper.findAll();
        MapperUtil.close(session);
        return list;
    }
}
